package com.boot.controller;

import com.boot.service.MenuService;
import com.boot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Controller
public class IndexController {

    @Autowired
    MenuService menuService;

    @Autowired
    UserService userService;

    @GetMapping("/index")
    public String index(Model model, @RequestParam(name = "current",defaultValue = "1")Integer current,
                        @RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize){
        model.addAttribute("menus",menuService.list());

        model.addAttribute("users",userService.list(current,pageSize));
        model.addAttribute("pages",userService.pages(current,pageSize));

        model.addAttribute("current",current);
        return "index";
    }

}
